home *** CD-ROM | disk | FTP | other *** search
/ Inter.Net 55-1 / Inter.Net 55-1.iso / CBuilder / Info / TeachU14 / SAMS / Code / Day12 / dbqueryu.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1998-02-08  |  2.8 KB  |  86 lines

  1. //---------------------------------------------------------------------------
  2. #include <vcl\vcl.h>
  3. #pragma hdrstop
  4.  
  5. #include "DbQueryU.h"
  6. //---------------------------------------------------------------------------
  7. #pragma package(smart_init);
  8. #pragma resource "*.dfm"
  9. TForm4 *Form4;
  10. //---------------------------------------------------------------------------
  11. __fastcall TForm4::TForm4(TComponent* Owner)
  12.   : TForm(Owner)
  13. {
  14. }
  15. //---------------------------------------------------------------------------
  16.  
  17. void __fastcall TForm4::FormCreate(TObject *Sender)
  18. {
  19.   Session->GetDatabaseNames(DBNamesComboBox->Items);
  20. }
  21. //---------------------------------------------------------------------------
  22.  
  23. void __fastcall TForm4::DBNamesComboBoxChange(TObject *Sender)
  24. {
  25.   if (Query1->Active)
  26.     Query1->Active = false;
  27.   if (Database1->Connected)
  28.     Database1->Close();
  29.   TablesComboBox->Text = "";
  30.   String DBName = DBNamesComboBox->Text;
  31.   Database1->DatabaseName = DBName;
  32.   if (Database1->IsSQLBased)
  33.     Session->GetTableNames(DBName, "",
  34.       false, true, TablesComboBox->Items);
  35.   else
  36.     Session->GetTableNames(DBName, "",
  37.       true, false, TablesComboBox->Items);
  38.   Query1->DatabaseName = DBName;
  39.   TablesComboBox->DroppedDown = true;
  40. }
  41. //---------------------------------------------------------------------------
  42.  
  43. void __fastcall TForm4::TablesComboBoxChange(TObject *Sender)
  44. {
  45.   if (TablesComboBox->Text == "") return;
  46.   String S = "Select * from " + TablesComboBox->Text;
  47.   Query1->SQL->Clear();
  48.   Query1->SQL->Add(S);
  49.   Query1->Open();
  50.   FieldsComboBox->Enabled = true;
  51.   ValueEdit->Enabled = true;
  52.   Query1->GetFieldNames(FieldsComboBox->Items);
  53.   FieldsComboBox->Text = FieldsComboBox->Items->Strings[0];
  54. }
  55. //---------------------------------------------------------------------------
  56. void __fastcall TForm4::SQLBtnClick(TObject *Sender)
  57. {
  58.   Query1->SQL->Clear();
  59.   Query1->SQL->Add(SQLEdit->Text);
  60.   Query1->Open();
  61. }
  62. //---------------------------------------------------------------------------
  63. void __fastcall TForm4::FilterBtnClick(TObject *Sender)
  64. {
  65.   TLocateOptions SearchOptions;
  66.   SearchOptions << loPartialKey;
  67.   Query1->Locate(FieldsComboBox->Text, ValueEdit->Text, SearchOptions);
  68. }
  69. //---------------------------------------------------------------------------
  70. void __fastcall TForm4::Database1Login(TDatabase *Database,
  71.       TStrings *LoginParams)
  72. {
  73.   LoginParams->Values["user name"] = UserNameEdit->Text;
  74.   LoginParams->Values["password"] = PasswordEdit->Text;
  75. }
  76. //---------------------------------------------------------------------------
  77. void __fastcall TForm4::SQLEditKeyDown(TObject *Sender, WORD &Key,
  78.       TShiftState Shift)
  79. {
  80.   if (Key == VK_RETURN) {
  81.     SQLBtnClick(Sender);
  82.     SQLEdit->SelectAll();
  83.   }
  84. }
  85. //---------------------------------------------------------------------------
  86.